<?php
/**
 * 微信封装类
 * User: narnia
 * Date: 2017/5/19
 * Time: 11:24
 */
namespace LancerWechat;
class WechatLancer extends WechatService
{
    /**
     * @var 微信授权类
     */
    //public $oauth;
    /**
     * @var 用户操作类
     */
    //public $user;
    /**
     * @var 微信支付类
     */
    //public $pay;

    /**
     * WechatOauth constructor.
     * @param array $config
     */

    public function __construct(array $config = [])
    {
        parent::createConfig($config);
        parent::init();
    }

    /**
     * 生成二维码
     * @param $json
     */
    public function qrcode($json) {
        $scene_str['scene'] = ['scene_str' => json_encode($json)];
        $postJson = [
            'expire_seconds' => 3000,
            'action_name' => 'QR_STR_SCENE',
            'action_info' => $scene_str
        ];
        $postJson = json_encode($postJson, JSON_UNESCAPED_UNICODE);
        $url = 'https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token='.$this->config['global']['access_token'];
        $result = json_decode(\LancerWechat\WechatFunction::curl($url, $postJson));
        \LancerWechat\WechatLog::write($this->config['log']['path'], $result);
        $result = 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket='.urlencode($result->ticket);
        return $result;
    }
}